extends EditorDebuggerPlugin

#region 属性
const DebuggerMessage = preload("res://addons/State_Chart/util/editor_debugger/editor_debugger_message.gd")
const DebuggerUI = preload("res://addons/State_Chart/util/editor_debugger/editor_debugger.gd")
var _debugger_ui_scene:PackedScene = preload("res://addons/State_Chart/util/editor_debugger/editor_debugger.tscn")
var _settings:EditorSettings = null
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
#endregion
#region 公共方法
func init(settings:EditorSettings):
	_settings = settings
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _has_capture(capture: String) -> bool:
	return capture == DebuggerMessage.MESSAGE_PREFIX
func _capture(message: String, data: Array, session_id: int) -> bool:
	var ui:DebuggerUI = get_session(session_id).get_meta("__state_charts_debugger_ui")
	match message:
		DebuggerMessage.STATE_CHART_EVENT_RECEIVED_MESSAGE:
			ui.event_received(data[0],data[1],data[2])
		DebuggerMessage.STATE_CHART_ADDED_MESSAGE:
			ui.add_chart(data[0])
		DebuggerMessage.STATE_CHART_REMOVED_MESSAGE:
			ui.remove_chart(data[0])
		DebuggerMessage.STATE_UPDATED_MESSAGE:
			ui.update_state(data[0], data[1])
		DebuggerMessage.STATE_CHART_EVENT_RECEIVED_MESSAGE:
			ui.event_received(data[0], data[1], data[2])
		DebuggerMessage.STATE_ENTERED_MESSAGE:
			ui.state_entered(data[0], data[1], data[2])
		DebuggerMessage.STATE_EXITED_MESSAGE:
			ui.state_exited(data[0], data[1], data[2])
		DebuggerMessage.TRANSITION_PENDING_MESSAGE:
			ui.transition_pending(data[0], data[1], data[2], data[3], data[4])
		DebuggerMessage.TRANSITION_TAKEN_MESSAGE:
			ui.transition_taken(data[0], data[1], data[2], data[3], data[4])
	return true
func _setup_session(session_id: int) -> void:
	var session = get_session(session_id)
	var debugger_ui:DebuggerUI = _debugger_ui_scene.instantiate()
	session.add_session_tab(debugger_ui)
	session.stopped.connect(debugger_ui.clear)
	session.set_meta("__state_charts_debugger_ui", debugger_ui)
	debugger_ui.init(_settings,session)
#endregion
